package models

import (
	"fresh-e-commerce/global"
	"gorm.io/gorm"
)

type Order struct {
	gorm.Model
	UserId       int64   `gorm:"type:int(10);comment:'用户id'"`
	OrderSn      string  `gorm:"type:char(36);comment:'订单编号'"`
	OrderPrice   float64 `gorm:"type:decimal(10,2);comment:'订单价格'"`
	OrderStatus  int64   `gorm:"type:tinyint(1);comment:'订单状态 1已支付 2未支付 3已取消'"`
	Payment      int64   `gorm:"type:tinyint(1);comment:'支付方式 1支付宝 2微信 3银行卡'"`
	ProductTitle string  `gorm:"type:varchar(30);comment:'商品标题'"`
	ProductPrice float64 `gorm:"type:decimal(10,2);comment:'商品单价'"`
	ProductNum   int64   `gorm:"type:int(10);comment:'商品购买数量'"`
}

func (*Order) TableName() string {
	return "order"
}

func (o *Order) OrderCreate() error {
	return global.DB.Debug().Create(&o).Error
}

func (o *Order) OrderList(uid int64) (order []*Order, err error) {
	if err = global.DB.Debug().Where("user_id=?", uid).Find(&order).Error; err != nil {
		return nil, err
	}
	return order, nil
}
